﻿<!DOCTYPE html>

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>系统用户</title>
    <meta name="renderer" content=padding>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/js/layui/css/layui.css" rel="stylesheet" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/framework/commonjs.js"></script>
    <script src="~/js/layui/layui.js"></script>

    <link rel="stylesheet" href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
    <script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>

    <script type="text/html" id="barDemo">

        <a title="编辑" href="javascript:;" lay-event="update"><i class="layui-icon">&#xe642;</i></a>
        <a title="删除" href="javascript:;" lay-event="del"><i class="layui-icon">&#xe640;</i></a>

    </script>

</head>
<style>
    .ui-dialog {
        overflow: visible;
    }
</style>
<body>
    <div class="layui-fluid" style="width:100%;">
        <ul lay-bar="disabled" class="mWebBanner">
            <li class="layui-nav-item" style="float:left;">
                <button id="btn-gjcx" type="button" name="btn-gjcx" onclick="openQueryWin()" style="border:0;background-color:transparent;color:#fff;cursor:pointer">
                    管理模板
                </button>
            </li>
            <li class="layui-nav-item" style="float:left;padding-left:3%">
                <button id="btn-update" type="button" name="btn_update" onclick="ServerPrint()" style="border:0;background-color:transparent;color:#fff;cursor:pointer">
                    服务器端打印
                </button>
            </li>
            <li class="layui-nav-item" style="float:left;padding-left:3%">
                <button id="btn-update" type="button" name="btn_update" onclick="LocalPreview()" style="border:0;background-color:transparent;color:#fff;cursor:pointer">
                    本地预览打印
                </button>
            </li>

        </ul>

        <div style="float:left;width:100%;">

            <div class="layui-card">
                <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                    <div class="layui-card-body" style="margin-top:5px">
                        <div class="layui-inline layui-show-xs-block">
                            <input value="A8-XL110" type="text" name="proCode" placeholder="存货编码" autocomplete="off" class="layui-input" id="proCode">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input value="哈麦xl 浴袍" type="text" name="proName" placeholder="存货名称" autocomplete="off" class="layui-input" id="proName">
                        </div>
                        <div class="layui-inline layui-show-xs-block" style="width:165px">
                            <select id="wareHouse" name="wareHouse" lay-search class="wareHouse" lay-filter="wareHouse">
                                <option value="">所属仓库</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-card-body" style="margin-top:5px">
                        <div class="layui-inline layui-show-xs-block">
                            <input value="66.7" type="number" name="proWeight" id="proWeight" placeholder="称重重量" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block" style="width:165px">
                            <select id="unit" name="unit">
                                @* <option value="">请选择单位</option> *@
                                <option value="kg">千克</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input value="1" type="number" name="number" id="number" placeholder="数量" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-card-body" style="margin-top:5px">
                        <div class="layui-inline layui-show-xs-block">
                            <input value="3" type="number" name="barNum" id="barNum" placeholder="条码打印个数" autocomplete="off" class="layui-input" onkeypress="return event.charCode >= 48" min="1">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input value="5" type="number" name="repeat" id="repeat" placeholder="重复次数" autocomplete="off" class="layui-input" onkeypress="return event.charCode >= 48" min="1">
                        </div>
                        <div class="layui-inline layui-show-xs-block" style="width:165px">
                            <select id="neighbor" name="neighbor">
                                <option value="yes">相同条码相邻</option>
                                <option value="no">多个自增队列</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-card-body" style="margin-top:5px">
                        <div class="layui-inline layui-show-xs-block" style="width:165px">
                            <select id="printerName" name="printerName" lay-search>
                                <option value="Microsoft Print to PDF">Microsoft Print to PDF</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block" style="width:165px">
                            <select id="templateName" name="templateName" lay-search>
                                @* <option value="">选择打印模板</option> *@
                                <option value="test.mb">test</option>
                            </select>
                        </div>
                    </div>

                    <input type="hidden" id="timeStamp" name="timeStamp" />
                    <input type="hidden" id="IsRemote" name="IsRemote" />
                    <input type="hidden" id="barType" name="barType" value="QC" />
                    <input type="hidden" id="barMemo" name="barMemo" value="条码编码" />

                </form>
                <div class="layui-card-body layui-table-body layui-table-main" id="layui-table-main">
                    <table class="layui-hide" id="userList" lay-filter="ulist"></table>
                </div>
            </div>


        </div>
    </div>
</body>

</html>
<script>
    var webCode = "";
    $(function () {
        webCode = getUrlVariable("menuCode");

        SetAutoComplete();
        WareHouseSelect("wareHouse", "");

        getPrinters();
    })

    // 获取服务器挂载的打印机，而不是网页客户端的打印机
    function getPrinters() {

    }

    function SetAutoComplete() {

        // 设置存货编码自动完成
        $("#proCode").autocomplete({
            source: function (request, response) {
                // var input = this.element;
                // $(input).css('color', 'red');

                // 用户在输入框实时输入的内容
                var userInput = request.term;
                var field = "proCode";

                // 用来筛选的语句
                var sql = "select top 10 {field} from fun_Inventory_Info where {field} like '%{filter}%' order by id";

                $.ajax({
                    url: "../Bar/Input_AutoComplete",
                    data: { filter: userInput, field: field, sql: sql },
                    dataType: "json",
                    type: "POST",
                    // async: false,
                    success: function (data) {

                        if (data.result) {
                            response(data.data);
                        }
                    }
                });

            },
            select: function (event, ui) {

                // 两者一样
                // var label = ui.item.label;
                var value = ui.item.value;

                var inv = {};
                inv.proCode = value;

                $.ajax({
                    url: "../Bar/InvInfo",
                    data: { invStr: JSON.stringify(inv) },
                    dataType: "json",
                    type: "POST",
                    // async: false,
                    success: function (data) {

                        if (data.result) {
                            SetInvInfo(data.data);
                        }
                    }
                });


            }
        });

        // 设置存货名称自动完成
        $("#proName").autocomplete({
            source: function (request, response) {
                // var input = this.element;
                // $(input).css('color', 'red');

                // 用户在输入框实时输入的内容
                var userInput = request.term;

                var field = "proName";

                // 用来筛选的语句
                var sql = "select top 10 {field} from fun_Inventory_Info where {field} like '%{filter}%' order by id";

                $.ajax({
                    url: "../Bar/Input_AutoComplete",
                    data: { filter: userInput, field: field, sql: sql },
                    dataType: "json",
                    type: "POST",
                    // async: false,
                    success: function (data) {

                        if (data.result) {
                            response(data.data);
                        }
                    }
                });

            },
            select: function (event, ui) {

                // 两者一样
                // var label = ui.item.label;
                var value = ui.item.value;

                var inv = {};
                inv.proName = value;

                $.ajax({
                    url: "../Bar/InvInfo",
                    data: { invStr: JSON.stringify(inv) },
                    dataType: "json",
                    type: "POST",
                    // async: false,
                    success: function (data) {

                        if (data.result) {
                            SetInvInfo(data.data);
                        }
                    }
                });


            }
        });
    }

    // 设置存货信息
    function SetInvInfo(inv) {
        $('#proCode').val(inv.proCode);
        $('#proName').val(inv.proName);
    }

    function LocalPreview() {

        const protocal_url_port = location.protocol + '//' + location.host;

        var date = new Date();
        var ms = date.getTime();

        $('#timeStamp').val(ms);
        $('#IsRemote').val('no');

        // 获取qForm内容
        var condition = JSON.stringify(FormToJson("qForm"));

        var loading = layer.msg('后台正在生成打印内容，请勿操作条码系统', { icon: 16, shade: 0.3, time: 0 });

        $.ajax({
            url: "../bar/PrintMuitiBarCodes",
            type: "post",

            data: {
                query: condition
            },
            success: function (data) {
                layer.close(loading);

                if (data.result) {
                    // 获取到下载文件的地址
                    // 拼接字符串，生成PowerShell脚本，启动脚本
                    var tempFilePath = protocal_url_port + data.data;
                    console.log("临时文件地址：");
                    console.log(tempFilePath);
                    if (data.data != '') {
                        StartPowerShellScript(tempFilePath);
                    } 

                    // DownloadAndOpenPreview(data);
                } else {
                    layer.msg(data.message);
                }

            }
        });
    }

    function ServerPrint() {

        var date = new Date();
        var ms = date.getTime();

        $('#timeStamp').val(ms);
        $('#IsRemote').val('yes');

        // 获取qForm内容
        var condition = JSON.stringify(FormToJson("qForm"));

        var loading = layer.msg('后台正在生成打印内容，请勿操作条码系统', { icon: 16, shade: 0.3, time: 0 });

        $.ajax({
            url: "../bar/PrintMuitiBarCodes",
            type: "post",

            data: {
                query: condition
            },
            success: function (data) {
                layer.close(loading);

                if (data.result) {

                    layer.msg("内容已加入服务器打印队列");
                    
                } else {
                    layer.msg(data.message);
                }

            }
        });
    }

    function StartPowerShellScript(downloadUrl) {
        $.ajax({
            url: "../Bar/GetPrintPreviewPowerShellScript",
            type: "post",
            data: { downloadUrl: downloadUrl },
            success: function (data) {
                if (data.result) {
                    console.log("printBarTools://" + data.data);
                    window.location.href = "printBarTools://" + data.data;
                }
            }
        });
    }
</script>
